package br.com.canvasForAll.model.dao;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import javax.ejb.Stateless;
import javax.inject.Named;
import javax.persistence.Query;

import br.com.canvasForAll.model.entity.Canvas;
import br.com.canvasForAll.model.entity.Postit;
import br.com.canvasForAll.model.generic.dao.GenericCrudDao;
import br.com.canvasForAll.model.repository.PostitRepository;

@Stateless
@Named(value="postitRepository")
public class PostitDao extends GenericCrudDao<Postit> implements PostitRepository {

	public PostitDao() {
		super(Postit.class);
	}

	@Override
	public Postit obterId(Long entityId) throws Exception {
		return super.obterPorId(entityId);
	}

	@Override
	public List<Postit> obterExemplo(String namedQuery, Map<String, Object> parametros) throws Exception {
		return super.obterPorExemplo(namedQuery, parametros);
	}

	@SuppressWarnings("unchecked")
	@Override
	public Collection<Postit> obterPostitCanvas(Canvas canvas) throws Exception {
		String sql = "SELECT p FROM Postit p WHERE p.canvas = :canvas";
		Query query = em.createQuery(sql);
		query.setParameter("canvas", canvas);
		
		Collection<Postit> lista = query.getResultList();
		
		return lista;
	}

}
